package com.ohimy.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import com.ohimy.entity.Group;
import com.ohimy.entity.Message;
import com.ohimy.entity.User;
import com.ohimy.service.impl.HomeService;

@Controller("homeAction")
public class HomeAction extends BaseAction {

	private static final long serialVersionUID = 2771712504910220440L;

	@Resource(name = "homeService")
	private HomeService homeService;

	private User user = new User();
	private Message message = new Message();
	private List<User> newJoinUser;
	private List<Group> groupList;
	private int msg;

	@Override
	public String execute() throws Exception {
		long uid = (long) super.getSession().getId();
		user = homeService.getUserById(uid);
		// 设置未读信息条数
		message.setToId(uid);
		msg = homeService.getUnreadMsg(message);
		// 得到最新加入的会员
		newJoinUser = homeService.getNewJoinUser();
		// 得到群组信息
		groupList = homeService.getGroupInHome(uid);

		result = "/WEB-INF/site/home/";
		return "ohimy";
	}

	// //////////////////////////////
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Message getMessage() {
		return message;
	}

	public void setMessage(Message message) {
		this.message = message;
	}

	public List<User> getNewJoinUser() {
		return newJoinUser;
	}

	public void setNewJoinUser(List<User> newJoinUser) {
		this.newJoinUser = newJoinUser;
	}

	public void setHomeService(HomeService homeService) {
		this.homeService = homeService;
	}

	public int getMsg() {
		return msg;
	}

	public void setMsg(int msg) {
		this.msg = msg;
	}

	public List<Group> getGroupList() {
		return groupList;
	}

	public void setGroupList(List<Group> groupList) {
		this.groupList = groupList;
	}

}